//
//  FMSBaseViewController.m
//  Founder_study
//
//  Created by founder on 14-7-30.
//  Copyright (c) 2014年 com.founder. All rights reserved.
//

#import "FMSBaseViewController.h"
#import "FMNavgationItem.h"
#import "ApplicationUtils.h"
@interface FMSBaseViewController ()<UIGestureRecognizerDelegate>

@end

@implementation FMSBaseViewController

-(void)dealloc {
    bgView = nil;
    self.customTitle = nil;
}

#pragma mark - 初始化nav的UI
- (void) initUI0 {
    float startY = 0;
    BOOL  IOS7Later =  [[[UIDevice currentDevice] systemVersion] compare:@"7.0" options:NSNumericSearch] != NSOrderedAscending;
    if ([self respondsToSelector:@selector(setAutomaticallyAdjustsScrollViewInsets:)]) {
        self.automaticallyAdjustsScrollViewInsets = NO;
    }
    if ([self respondsToSelector:@selector(setEdgesForExtendedLayout:)]) {
        self.edgesForExtendedLayout = UIRectEdgeBottom;
    }

    self.view.backgroundColor = [UIColor whiteColor];
    bgView = [[UIView alloc] initWithFrame:CGRectMake(0, startY, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height-20-44)];
    bgView.userInteractionEnabled = YES;
//    bgView.backgroundColor = [UIColor colorWithRed:(float)0xF5/0xFF green:(float)0xF4/0xFF blue:(float)0xD4/0xFF alpha:1.0f];//黄色
    bgView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:bgView];
    
    //添加返回按钮
	if (self.navigationController.viewControllers.count>=1) {
        FMNavgationItem* leftItem = [[FMNavgationItem alloc] init];
        [leftItem.backButton addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];
        self.navigationItem.leftBarButtonItems = [leftItem getNavgationItemWithType:WRNavgationTypeLeft Ima:[ApplicationUtils getLocalImage:@"Navigation-Bar_Return_btn_@2x"] ImaHighlight:[ApplicationUtils getLocalImage:@"Navigation-Bar_Return_btn_@2x"] title:@""];
        if (IOS7Later) {
            self.navigationController.interactivePopGestureRecognizer.delegate = self;
        }
    }
    

}

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    [bgView endEditing:YES];
}


- (void)viewDidLoad {
    [super viewDidLoad];
    [self initUI0];
}
- (UIStatusBarStyle)preferredStatusBarStyle {
    return UIStatusBarStyleLightContent;
}

#pragma mark - 按钮
-(void)back{
    [self.navigationController popViewControllerAnimated:YES];
}
-(void)setCustomTitle:(NSString *)customTitle{
    self.navigationItem.title = customTitle;
}

//#pragma mark - 横竖屏切换
//- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
//    //如果要初始化为竖屏
//    return UIInterfaceOrientationIsPortrait(toInterfaceOrientation);
//    
//}
//
//- (BOOL)shouldAutorotate {
//    
//    return YES;
//    
//}
//
//- (NSUInteger)supportedInterfaceOrientations {
//    
//    return UIInterfaceOrientationMaskPortrait;//只支持这一个方向(正常的方向)
//    
//}

//- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer
//{
//    if (self.navigationController.viewControllers.count == 1)//关闭主界面的右滑返回
//    {
//        return NO;
//    }
//    else
//    {
//        return YES;
//    }
//}
@end
